package com.dgshanger.sanhxiaofeisc.mvp.presenter

import com.dgshanger.sanhxiaofeisc.entity.ShopDetailsEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.ShopDetailsContract
import com.dgshanger.sanhxiaofeisc.mvp.model.ShopDetailsModel
import com.xx.baseuilibrary.mvp.BaseMvpPresenter
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * Created by JacobHHH on 2018/4/18.
 */
class ShopDetailsPresenter : BaseMvpPresenter<ShopDetailsContract.Model,ShopDetailsContract.View>() , ShopDetailsContract.Presenter{


    override fun cancelCollect(shop_id: String?) {
        getModel().cancelCollect(shop_id,object : XxBaseHttpObserver<Any?>(){
            override fun onCompleted(msg: String?, entity: Any?) {
                getView()?.onCancelCollectSuccess(msg)
            }

            override fun onError(error: String?) {
               getView()?.showToast(error)
            }

            override fun onStart() {
                getView()?.showLoadingDialog("取消收藏")
            }

            override fun onFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun collectShop(shop_id: String?) {

        getModel().collectShop(shop_id,object : XxBaseHttpObserver<Any?>(){

            override fun onCompleted(msg: String?, entity: Any?) {
                getView()?.onCollectShopSuccess(msg)
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onStart() {
                getView()?.showLoadingDialog()
            }

            override fun onFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun loadData(shop_id: String?) {
        getModel().loadData(shop_id,object : XxBaseHttpObserver<ShopDetailsEntity>(){

            override fun onCompleted(msg: String?, entity: ShopDetailsEntity?) {
                getView()?.setData(entity)
            }

            override fun onError(error: String?) {
                getView()?.onDataFailure(error)
                getView()?.showToast(error)
            }

            override fun onStart() {

            }

            override fun onFinish() {

            }

        })
    }

    override fun createModel(): ShopDetailsContract.Model = ShopDetailsModel()
}